package com.qdu.servlet;

import com.qdu.entity.Comment;
import com.qdu.entity.User;
import com.qdu.service.CommentService;
import com.qdu.service.impl.CommentServiceImpl;
import java.io.IOException;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Ice
 */
@WebServlet("/adcs")
public class AddCommentServlet extends HttpServlet {

    CommentService commentService = new CommentServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        User user = new User();
        HttpSession session = req.getSession();
        user = (User) session.getAttribute("user");
        int uid = user.getId();// 得到该登录用户的id号

        String mbid = req.getParameter("mbid");

        //String contents = new String(req.getParameter("contents").getBytes("iso-8859-1"), "utf-8");  //需要表单内输入
        String contents = req.getParameter("contents");  //需要表单内输入

        Date mydate = new Date();

        float rating = Float.parseFloat(req.getParameter("rating"));  //需要表单内输入（下拉列表1-5）

        Comment comment = new Comment(uid, mbid, contents, mydate, rating);

        int rows = commentService.addNewComment(comment);

        //生成响应内容，返回受影响的行数，用于判断是否添加成功      
        resp.getWriter().println(rows);

    }

}
